const chokidar = require('chokidar');
const WebSocket = require('ws');
const watcher = chokidar.watch('.', {
  ignored: /node_modules|\.git|[\/\\]\./
});

var wss = new WebSocket.Server({port: 8000});
wss.on('connection', (ws) => {
  	watcher
		.on('add', path => console.log(`File ${path} added`))
		.on('change', path => console.log(`File ${path} has been changed`))
		.on('unlink', path => console.log(`File ${path} has been moved`))
		.on('all', async (event, path) => {
			setTimeout(function() {
		      // Simple Live Reload
				ws.send('reload');			
			}, 500);
		})

	console.log('HMR Client is Ready');
})
console.log('HMR Server is started...');
